<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 解构赋值：将数组或者对象的数据提取出来赋值给变量，这个过程叫做解构赋值
        // let [要声明的变量1，变量2，...]=数组
        let arr = ["张三", "李四", "王五"];
        let [a, b, c] = arr;
        console.log(a, b, c)
        // 自动赋值  将赋值符号左侧数组写入变量，声明出来，并使用符号右侧的数组对应数组项给变量赋值



        // 完全解构
        // 赋值的数组项=变量
        let arr1 = ["清许", "初见", "海文"];
        let [q, w, e] = arr1;
        console.log(q, w, e)


        // 不完全解构
        // 赋值的数组项>变量
        let arr2 = ["王一博", "赵丽颖", "大张伟", "杨幂"]
        // let [r,y]=arr2
        // console.log(r,y)

        // 设置缺省值
        let [r, , y] = arr2
        console.log(r, y)



        // 解构失败
        // 赋值的数组项<变量
        let arr3 = ["王一博", "杨幂"];
        let [f, g, h,] = arr3;
        console.log(f, g, h)



        // 解构默认值
        let arr4 = ["张三", "李四", "王五"];
        // let [z, x, k, v = "赵六"] = arr4;
        // console.log(z, x, k, v = "赵六")
        let [z, k, v = "赵六"] = arr4;
        console.log(z, k, v)


    </script>
</body>

</html>